package yanglib.message;

import java.io.IOException;
import java.nio.ByteBuffer;

/**
 * Created with IntelliJ IDEA.
 * User: user
 * Date: 9/4/14
 * Time: 7:50 PM
 * To change this template use File | Settings | File Templates.
 */
public class Message {

    private int type;
    private int sender;

    public Message(ByteBuffer buffer){
        try{
            this.deserialize(buffer);
        }
        catch(IOException e){
            e.printStackTrace();
            System.exit(-1);
        }
    }
    public Message(int type, int sender){
        this.type = type;
        this.sender = sender;
    }

    public int getType(){
        return this.type;
    }

    public int getSender(){
        return this.sender;
    }

    public void serialize(ByteBuffer buffer){
        buffer.putInt(this.type);
        buffer.putInt(this.sender);
    }

    public void deserialize(ByteBuffer buffer) throws IOException{
        this.type = buffer.getInt();
        this.sender = buffer.getInt();
    }
}
